﻿
@{
    ViewBag.Title = "User";
    Layout = "~/Views/Shared/Admin/_LayoutAdmin.cshtml";
}
@using AIKE_Model;
<!--用户管理-->
<link href="~/Common/layUI/theme/layui.css" rel="stylesheet" />
<script src="~/Common/layUI/layer.js"></script>
<div class="panel panel-default">

    <div class="panel-heading"><h1>用户管理</h1></div>

    <table class="table">
        <thead>
            <tr>
                <th>编号</th>
                <th>用户类型</th>
                <th>账号</th>
                <th>真实姓名</th>
                <th>手机号码</th>
                <th>账号余额</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @*<tr>
                    <td>001</td>
                    <td>Rammohan </td>
                    <td>Reddy</td>
                    <td>A+</td>
                    <td>
                        <button class="btn btn-primary" data-toggle="modal" data-target="#myModal">修改</button>

                        <button class="btn btn-danger" data-toggle="modal" data-target="#myModal2">删除</button>
                    </td>
                </tr>*@

            @foreach (AdminUsers u in (List<AdminUsers>)ViewData["userlist"])
            {
                <tr>
                    <td>@u.ID</td>
                    <td>@u.UserType</td>
                    <td>@u.AccountNumber</td>
                    <td>@u.RealName</td>
                    <td>@u.Phone</td>
                    <td>@u.AccountBalance</td>
                    <td>
                        <button class="btn btn-primary edit" data-toggle="modal" data-target="#myModal">修改</button>

                        <button class="delet_btn btn btn-danger" data-toggle="modal" data-target="#myModal2">删除</button>
                        
                    </td>
                </tr>
            }

        </tbody>
    </table>


    <!--模态框------------------------------------------------------------------------------------------------------>



    <form method="post" action="#" class="form-horizontal" role="form" id="myForm" onsubmit="return ">
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <!--  定义模态框，过渡效果为淡入，id为myModal,tabindex=-1可以禁用使用tab切换，aria-labelledby用于引用模态框的标题，aria-hidden=true保持模态框在触发前窗口不可见  -->
            <div class="modal-dialog">
                <!--  显示模态框对话框模型（若不写下一个div则没有颜色）  -->
                <div class="modal-content">
                    <!--  显示模态框白色背景，所有内容都写在这个div里面  -->

                    <div class="btn-info modal-header">
                        <!--  模态框标题  -->
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <!--  关闭按钮  -->
                        <h4>修改用户信息</h4>
                        <!--  标题内容  -->
                    </div>

                    <div class="modal-body">
                        <!--  模态框内容，我在此处添加一个表单 -->
                        <form class="form-horizontal" role="form">

                            <div class="form-group">
                                <label for="uname" class="col-sm-2 control-label">用户类型</label>
                                <div class="col-sm-9">
                                    <input type="text" id="userType" name="userType" class="form-control well" placeholder="用户类型" />
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="phone" class="col-sm-2 control-label">手机号码</label>
                                <div class="col-sm-9">
                                    <input type="text" id="phone" name="phone" class="form-control well" placeholder="用户类型" />
                                </div>
                            </div>


                            <div class="form-group">
                                <label for="realName" class="col-sm-2 control-label">真实姓名</label>
                                <div class="col-sm-9">
                                    <input type="text" id="realName" name="realName" class="form-control well" placeholder="真实姓名" />
                                </div>
                            </div>

                        </form>
                    </div>

                    <div class="modal-footer">
                        <!--  模态框底部样式，一般是提交或者确定按钮 -->
                        <button type="submit" class="btn btn-info" id="editBtn">确定</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>

                </div><!-- /.modal-content -->
            </div>
        </div> <!-- /.modal -->


    </form>
</div>

<!--第二--------------------------------------->

<form method="post" action="#" class="form-horizontal" role="form" id="myForm" onsubmit="return ">
    <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <!--  定义模态框，过渡效果为淡入，id为myModal,tabindex=-1可以禁用使用tab切换，aria-labelledby用于引用模态框的标题，aria-hidden=true保持模态框在触发前窗口不可见  -->
        <div class="modal-dialog">
            <!--  显示模态框对话框模型（若不写下一个div则没有颜色）  -->
            <div class="modal-content">
                <!--  显示模态框白色背景，所有内容都写在这个div里面  -->

                <div class="btn-info modal-header">
                  
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                  
                    是否删除该用户？
                </div>

                <div class="modal-footer">
                    <!--  模态框底部样式，一般是提交或者确定按钮 -->
                    <button type="submit" class="DeleteUsers btn btn-info">确定</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>

            </div><!-- /.modal-content -->
        </div>
    </div> <!-- /.modal -->

    <script src="~/Lib/Admin/js/apend.js"></script>
</form>




<!--模态框------------------------------------------------------------------------------------------------------>

<script>
    $(function () {

        $(".edit").click(function () {

           // alert($(this).parents("tr").children("td:eq(0)").text())
            $.ajax({
                url: "../Admin/Edit",
                dataType: "json",
                data: { "id": $(this).parents("tr").children("td:eq(0)").text() },
                success: function (data) {
                    var type = data.UserType;
                    var phone = data.Phone;
                    var RealName = data.RealName;

                    $("#realName").val(RealName);
                    $("#userType").val(type);
                    $("#phone").val(phone);

                },
                error: function () {

                }

            });

        });

    });
</script>



<script>
    $(function () {

        $("#editBtn").click(function () {
            $.ajax({
                url: "../Admin/Edits",
                dataType: "json",
                data: { "type": $("#userType").val(), "realName": $("#realName").val(), "phone": $("#phone").val() },
                success: function (data) {
                    if (parseInt(data) == 1) {
                        layer.msg("修改成功！", { icon: 1 });
                        setTimeout("location.href='../Admin/User'", 2000);
                    }
                    else {
                        layer.msg("修改失败", { icon: 2 });
                    }
                },
                error: function () {
                    layer.msg("修改失败", { icon: 2 });
                }

            });

        });

    });
</script>


<!--删除用户-->
<script>
    $(function () {
        var u_id;
        $(".delet_btn").click(function () {
            u_id=$(this).parents("tr").children("td:eq(0)").text();
        });
        $(".DeleteUsers").click(function () {
            $.ajax({
                url: "../Admin/DeleteUser",
                dataType: "json",
                data: { "id": u_id },
                success: function (data) {
                    if (parseInt(data) == 1) {
                        layer.msg("删除成功！", { icon: 1 });
                        setTimeout("location.href='../Admin/User'", 2000);
                    }
                    else {
                        layer.msg("删除失败", { icon: 2 });

                    }
                },
                error: function () {
                    layer.msg("删除失败", { icon: 2 });
                }

            });


        });

    });
</script>